const commander = require("commander")

const { version } = require("../config/command")

const path = require("path")

let commandMap = {
        create: {
            alias: "c",
            description: "创建命令",
            example: ["ling-cli create xxx -------创建项目"]
        },
        "*": {
            alias: "",
            description: "command is not found",
            example: []
        }
    }
    // 遍历命令 --help组
Object.keys(commandMap).forEach(cmd => {
    commander.command(cmd).description(commandMap[cmd].description).action(() => {
        if (cmd == "*") {
            console.warn("command is not found")
        } else {
            const action_path = path.join(__dirname, "../", "action", cmd)
            require(action_path)(cmd, ...process.argv.slice(3))
        }
    })
});
// Exapmle组
commander.on("--help", () => {
        console.log("examples:\n");
        Object.keys(commandMap).forEach(cmd => {
            commandMap[cmd].example.forEach(v => {
                console.log(v)
            })
        });
    })
    // version: 内置属性，版本号
commander.version(version).parse(process.argv)